//
//  TTReachability.h
//  Tint
//
//  Created by Kevin Wu on 8/22/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <netinet/in.h>
#import "Core/Core.h"


#define TTReachabilityStatusChangedNotification @"TTReachabilityStatusChangedNotification"



typedef enum {
    TTNetworkNotReachable = 0, 
    TTNetworkReachableViaWiFi, 
    TTNetworkReachableViaWWAN
} TTNetworkStatus;




@interface TTReachability : NSObject {
    SCNetworkReachabilityRef _reachabilityRef;
}

- (id)initWithNetworkReachability:(SCNetworkReachabilityRef)reachabilityRef;

+ (TTReachability *)sharedObject;
+ (BOOL)hasSharedObject;
+ (void)destroySharedObject;

// Use to check the reachability of a particular host name.
+ (TTReachability *)reachabilityWithHostName:(NSString *)hostName;

// Use to check the reachability of a particular IP address.
+ (TTReachability *)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress;

// Use to check whether the default route is available.
// Should be used by applications that do not connect to a particular host.
+ (TTReachability *)reachabilityForInternetConnection;



// Start listening for reachability notifications on the current run loop.
- (BOOL)startNotifier;
- (void)stopNotifier;

- (TTNetworkStatus)networkStatus;


// WWAN may be available, but not active until a connection has been established.
// WiFi may require a connection for VPN on Demand.
- (BOOL)connectionRequired;


- (BOOL)isNetworkReachable;
- (BOOL)isNetworkReachableViaWiFi;
- (BOOL)isNetworkReachableViaWWAN;

@end
